const { ErrorModel } = require("../model/ResModel")

async function loginCheck(ctx, next) {
    if(ctx.session.userInfo) {
        await next()
    } else {
        ctx.body = ErrorModel.loginFailInfo()
    }
}

async function loginRedirect(ctx, next) {
    if(ctx.session.userInfo) {
        await next()
    } else {
        ctx.redirect(`/login?url=${encodeURIComponent(ctx.url)}`)
    }
}

module.exports = {
    loginCheck,
    loginRedirect
}